package com.example.smartwaterapi.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.function.Function;

/**
 * 设备实体类
 */
@Data
@TableName(value = "devices", autoResultMap = true)
@Accessors(chain = true)
public class Device implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 设备ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 设备序列号
     */
    private String deviceSn;

    /**
     * MAC地址
     */
    private String macAddress;

    /**
     * 蓝牙设备ID（真实标识符）
     */
    private String deviceId;

    /**
     * 绑定用户ID
     */
    private Long userId;

    /**
     * 设备名称
     */
    private String deviceName;

    /**
     * 设备型号
     */
    private String model;

    /**
     * 电池电量
     */
    private Integer batteryLevel;

    /**
     * 当前水量(ml)
     */
    private Integer currentVolume;

    /**
     * 水温
     */
    private Double waterTemperature;

    /**
     * 是否在线
     */
    private Integer isOnline;

    /**
     * 最后心跳时间
     */
    private LocalDateTime lastHeartbeat;

    /**
     * 设备时区
     */
    private String deviceTimezone;

    /**
     * 最后同步时间戳(Unix时间戳)
     */
    private Long lastSyncTimestamp;

    /**
     * 设备时间偏移量(秒)
     */
    private Integer deviceTimestampOffset;

    /**
     * 时间戳校准时间
     */
    private LocalDateTime timestampCalibratedAt;

    /**
     * 是否启用NTP时间同步
     */
    private Integer ntpSyncEnabled;

    /**
     * 设备认证令牌
     */
    private String deviceToken;

    /**
     * 最后认证时间戳
     */
    private Long lastAuthTimestamp;

    /**
     * 认证失败次数
     */
    private Integer authFailureCount;

    /**
     * 设备是否被锁定
     */
    private Integer isLocked;

    /**
     * 设备设置JSON
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    private Object settings;

    /**
     * 当前表盘ID
     */
    private Long currentWatchfaceId;

    /**
     * 表盘设置
     */
    @TableField(typeHandler = JacksonTypeHandler.class)
    private Object watchfaceSettings;

    /**
     * 设备状态
     */
    private Integer status;

    /**
     * 创建时间
     */
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    private LocalDateTime updatedAt;
    
    /**
     * 表盘背景图片URL
     */
    private String dialBackgroundUrl;
    
    // Static fields for lambda cache support
    public static final Function<Device, Long> ID = Device::getId;
    public static final Function<Device, String> DEVICE_SN = Device::getDeviceSn;
    public static final Function<Device, String> DEVICE_ID = Device::getDeviceId;
    public static final Function<Device, String> MAC_ADDRESS = Device::getMacAddress;
    public static final Function<Device, Long> USER_ID = Device::getUserId;
    public static final Function<Device, Integer> IS_ONLINE = Device::getIsOnline;
    public static final Function<Device, Integer> BATTERY_LEVEL = Device::getBatteryLevel;
    public static final Function<Device, Integer> CURRENT_VOLUME = Device::getCurrentVolume;
    public static final Function<Device, Double> WATER_TEMPERATURE = Device::getWaterTemperature;
} 